package com.heraleign.boot.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class Swagger3Config {
    @Bean
    public Docket apiConfig(){

        return new Docket(DocumentationType.OAS_30)
            .apiInfo(apiInfo())
            .select()
            // 设置通过什么方式定位到需要生成文档的接口
            // 定位了方法上的ApiOperation
            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
            // 接口的URL路径，any表示全部路径
            .paths(PathSelectors.any())
            //.paths(PathSelectors.regex("/student/**"))
            .build();
    }


    /**
     * swagger访问地址
     * http://localhost:8017/swagger-ui/index.html
     */


    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
            .title("SpringBoot项目")
            .description("SpringBoot项目的Swagger测试")
            .contact(new Contact("luoyw","http://heraleign.com","heraleign@aliyun.com"))
            .version("1.0")
            .build();
    }

}
